<template>
  <view class="container">
    <!-- <div class="header">
            <div v-for="(tag,index) in list" :key="index" :class="{active: tagIndex === index}" @click="switchTag(index)">{{tag}}</div>
        </div> -->
    <div v-if="serviceList.length" class="service-list">
      <div
        class="service-item"
        v-for="(item, index) in serviceList"
        :key="index"
        @click="toServiceDetail(item.id)"
      >
        <div
          class="service-pic"
          :style="{ 'background-image': `url(${item.avatar})` }"
        ></div>
        <div class="service-info">
          <div class="service-info_top">
            <div class="title">{{ item.name }}</div>
            <!-- <div class="desc">{{item.expert}}</div> -->
          </div>
          <div class="service-info_bottom">
            <div v-if="type == 1" class="price">
              ￥{{ item.totalFee }}/<span style="font-size: 26rpx">{{
                item.nursingServiceDetailList[0].chargeMethod
                  | chargeMethodFilter
              }}</span>
            </div>
            <div v-else class="price">
              ￥{{ item.totalFee }}/<span style="font-size: 26rpx">{{
                item.homeServiceDetailList[0].chargeMethod | chargeMethodFilter
              }}</span>
            </div>
            <div class="num">已服务 {{ item.alearServiceByNums }}</div>
          </div>
        </div>
      </div>
    </div>
    
    <!-- 空数据 -->
    <div v-else class="empty">
        <u-empty text="暂无服务内容" mode="list" :margin-top="200"></u-empty>
    </div>

    <u-toast ref="uToast" />
  </view>
</template>

<script>
import Vue from "vue";
import { getNursingListAPI, getHousekeepingListAPI } from "../../api/service";
export default Vue.extend({
  data() {
    return {
      list: ["护工", "家政", "就医陪同"],

      serviceList: [],
      tagIndex: 0,
      classIndex: 0,
      type: 1, // 1护工 2家政
    };
  },
  filters: {
    chargeMethodFilter(v) {
      let arr = ["次", "时", "天", "月"];
      return arr[v - 1];
    },
  },
  onLoad(options) {
    this.type = options.type;
    let api = this.type == 1 ? getNursingListAPI : getHousekeepingListAPI;
    api()
      .then((res) => {
        console.log("res", res);
        if (this.type == 1) {
          this.serviceList = res.nursingServiceList;
        } else {
          this.serviceList = res.homeServiceList;
        }
      })
      .catch((err) => {
        this.$refs.uToast.show({
          title: err,
          type: "error",
        });
      });
  },
  methods: {
    switchTag(index) {
      this.tagIndex = index;
      this.classIndex = 0;
    },
    switchClass(index) {
      this.classIndex = index;
    },
    toServiceDetail(id) {
      this.$u.route("pages/serviceDetail/serviceDetail", {
        id: id,
        type: this.type,
      });
    },
  },
});
</script>

<style lang="scss" scoped>
@import "../../assets/scss/common.scss";

.container {
  min-height: 100vh;
  background-color: #f6f6f6;
}

.empty{
    overflow: hidden;
}

.header {
  width: 100%;
  display: flex;
  padding: 10px;
  justify-content: space-around;
  background-color: #fff;
  margin-bottom: 10px;
  div {
    line-height: 30px;
    border-radius: 30rpx;
    padding: 0 20px;
    transition-duration: 0.2s;
    &.active {
      color: #fff;
      background-color: $theme-color;
    }
  }
}
.service-list {
  padding: 20rpx 10px 0;
  .service-item {
    margin-bottom: 10px;
    display: flex;
    background-color: #fff;
    padding: 12px 15px;
    border-radius: 5px;
    .service-pic {
      width: 120px;
      height: 80px;
      background-size: cover;
      background-position: center;
      flex: none;
      border-radius: 5px;
      margin-right: 15px;
    }
    .service-info {
      flex: auto;
      display: flex;
      flex-direction: column;
      .service-info_top {
        flex: auto;
        .title {
          font-size: 16px;
          color: #534f4f;
          margin-bottom: 5px;
        }
        .desc {
          font-size: 12px;
          color: #707070;
        }
      }
      .service-info_bottom {
        flex: none;
        display: flex;
        justify-content: space-between;
        display: flex;
        align-items: baseline;
        .price {
          font-size: 17px;
          color: #fb7133;
        }
        .num {
          font-size: 13px;
          color: #a7a7a7;
        }
      }
    }
  }
}
</style>
